package com.nosnow.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nosnow.common.utils.R;
import com.nosnow.edu.entity.EduCourse;
import com.nosnow.edu.entity.EduTeacher;
import com.nosnow.edu.service.EduCourseService;
import com.nosnow.edu.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author by bingHeng
 * @version 1.0
 * @Create 2020/5/9 23:10
 */
@RestController
@RequestMapping("/edu/front/lecturer")
public class TeacherFrontController {

    @Autowired
    private EduTeacherService eduTeacherService;

    @Autowired
    private EduCourseService eduCourseService;

    // 分页查询讲师列表
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable long page, @PathVariable long limit) {
        // 封装分页对象
        Page<EduTeacher> pageTeacher = new Page<>(page, limit);

        // 获取数据
        Map<String, Object> map = eduTeacherService.getTeacherFrontList(pageTeacher);

        // 返回分页中的所有数据
        return R.ok().data(map);
    }

    // 讲师详情
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId) {
        // 根据讲师查询讲师基本信息
        EduTeacher teacher = eduTeacherService.getById(teacherId);

        // 根据讲师Id查询讲师课程信息
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id", teacherId);
        List<EduCourse> courseList = eduCourseService.list(wrapper);

        return R.ok().data("teacher", teacher).data("courseList", courseList);
    }
}
